/**
 * @param {string} keyboard
 * @param {string} word
 * @return {number}
*/
var calculateTime = function(keyboard, word) {
  let moveIndex = [], result = 0;
  for(let i = 0; i < word.length; i++) {
    moveIndex.push(keyboard.indexOf(word[i]));
  }
  for(let i = 0; i < moveIndex.length; i++) {
    if(i == 0) {
      result += moveIndex[i];
    } else {
      result += Math.abs(moveIndex[i] - moveIndex[i - 1]);
    }
  }
  return result;
};
let keyboard = "abcdefghijklmnopqrstuvwxyz", word = "cba";
console.log(calculateTime(keyboard, word));
keyboard = "pqrstuvwxyzabcdefghijklmno", word = "leetcode";
console.log(calculateTime(keyboard, word));
